home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / rng.exe / README < prev    next >
Text File  |  1991-12-19  |  3KB  |  72 lines

  1. These files contain source to two random number generators that I have
  2. found very useful in my work.  I've used the Knuth generator for
  3. almost a decade now and found it to be very satisfactory.  I've been
  4. using the Marsaglia generator for only about a year, but it also
  5. works very well.  The Marsaglia generator is supposedly (as of a year
  6. ago) the best random number generator known.  It apparently passes
  7. all known statistical tests for randomness.  I say apparently because
  8. I have not validated it myself, nor have I examined the original
  9. publication.  I'm just repeating the information in random.doc.  I
  10. have no reason not to believe what the people I've cribbed from wrote,
  11. but don't blame me if you find a problem that I've missed.
  12.  
  13. The source files for the code I actually use is in RAN.H and RAN.C.  A
  14. sample program illustrating how to use the generators (and to test
  15. the Marsaglia generator) is in sample.c.  You should be able to run
  16. sample simply by compiling it, ran.c, and linking the two together. 
  17. I've tried to write the code in a very portable way, and I have
  18. successfully used it under various versions of Microsoft C, cc and
  19. gcc (on a Sun SPARCstation 2), and Waterloo C and IBM C (on an IBM
  20. 3090 mainframe).  The code from which the Marsaglia generator is
  21. derived is found in RANDOM.FOR (the original FORTRAN version by David
  22. LaSalle) and RANDOM-C.C (the C translation by Jim Butler).  The
  23. documentation files that accompanied these is also included (in
  24. RANDOM.DOC and RANDOM-C.DOC).
  25.  
  26. Notice that I read the random number seed from a file in each
  27. execution and that the value of this seed is returned from setup(). I
  28. do this so that when I am developing a simulation I can duplicate the
  29. exact pseudo-random sequence that caused a problem.
  30.  
  31. Notice also that either RAN_KNU or RAN_MAR needs to be explicitly
  32. defined in RAN.H.  RAN_KNU selects the Knuth random number generator.
  33. RAN_MAR selects the Marsaglia generator.
  34.  
  35. To test the Marsaglia generator, just compile and link sample.c and
  36. ran.c as is.  When you execute the program you'll be prompted to
  37. enter two random number seeds.  The first number you enter must be
  38. 1802, and the second must be 9373.  After a few seconds a message
  39. will print out indicating the correct answer and the answer your
  40. compilation produced.  The two should match exactly.  If they don't,
  41. there's some kind of problem.  Alternatively, you can create RAND.INT
  42. as a standard ASCII text file.  Then put in a single line that contains
  43. only the number 614270730.
  44.  
  45. If the numbers don't match, the most likely cause is that you ran the
  46. executable once already and the seed read from RAND.INT is not 
  47. 614270730.
  48.  
  49. Enjoy these tools at your own risk.  Although I've been happy with 
  50. their performance, I can't and I won't accept responsibility for any
  51. pain they might cause you.
  52.  
  53. -- Kent E. Holsinger
  54.  
  55.  
  56.  
  57.  
  58. Files included in this package:
  59.  
  60.     Source for Knuth and Marsaglia random number generators
  61.         ran.h   
  62.         ran.c
  63.     Source for program to illustrate use of the generators and to test
  64.         sample.c
  65.     Source from which the C version of the Marsaglia generator was derived
  66.         random.for        Original Fortran version
  67.         random-c.c        C language version
  68.     Documentation
  69.         random.doc
  70.         random-c.doc
  71.  
  72.